import http from '../../utils/request'
import {  SAVE_PROFILE, SAVE_USER } from '../action_type/profile'

/**
 * 保存用户信息
 * @param {*} payload
 * @returns
 */
export const seveUser = (payload) => {
  return {
    type: SAVE_USER,
    payload,
  }
}
/**
 * 获取用户信息
 * @returns Promise
 */
export const getUser = () => {
  return async (dispatch) => {
    // 发送请求
    const res = await http({
      url: `/user`,
      method: 'get',
    })
    // console.log(res)
    dispatch(seveUser(res.data.data))
  }
}
export const seveProfile = (payload) => {
  return {
    type: SAVE_PROFILE,
    payload,
  }
}
export const getProfile = () => {
  return async (dispatch) => {
    // 发送请求
    const res = await http({
      url: `/user/profile`,
      method: 'get',
    })
    // console.log(res.data)
    dispatch(seveProfile(res.data.data))
  }
}

